package com.yc.http;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Title:<br>
 * Description: <br>
 * Author:陈圆(chenyuan@bosssoft.com.cn) <br>
 * Date:2020/9/10
 */
public class URIDemo {
    public static void main(String[] args) {
        URL url;
        try {
            url = new URL("http://www.baidu.com");
            //打开到此 URL 的连接并返回一个用于从该连接读入的 InputStream。
            InputStream in = url.openStream();// 其内部也调用了openConnection()
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int len = -1;
            // 读取内容不含响应头
            while ((len = in.read(buffer)) != -1)
            {
                output.write(buffer, 0, len);
            }
            System.err.println(new String(output.toByteArray()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
